package string_3_10;

import java.util.Arrays;
import java.util.Locale;

public class StringTest {
    public static void main(String[] args) {
        //用常量字符串构造一个字符串对象
        String s1 = new String("wang shuang xi");
        //一个字符串对象构造另一个字符串对象
        String s2 = new String(s1);
        System.out.println(s1);
        System.out.println(s2);
        //字符数组
        char[] s3 = new char[]{'h','e','l','l','o',' ','w','o','r','l','d'};
        System.out.println(s3);
        //用字符数组构造字符串
        String s4 = new String(s3);
        System.out.println(s4);
        System.out.println(s1 == s2);
        //比较两个字符是否相同，相同返回true，不同返回false
        System.out.println(s1.equals(s2));
        System.out.println(s2.equals(s4));
        //比较两个字符串，相同返回0，不同返回非0
        System.out.println(s1.compareTo(s2));
        System.out.println(s1.compareTo(s4));

        System.out.println(s1.charAt(1));
        //索引越界
        //System.out.println(s1.charAt(20));

        System.out.println(s1.indexOf("shu"));
        System.out.println(s1.indexOf('m'));

        System.out.println(s1.lastIndexOf("xi"));
        System.out.println(s1.lastIndexOf("xi", 10));

        String s5 = String.valueOf(new Student("Hanmeimei", 18));
        System.out.println(s5);
        //数字专字符串
        String s6 = String.valueOf(12.35);
        System.out.println(s6);
        //字符串专数字
        double num = Double.parseDouble(s6);
        System.out.println(num);

        //字符串专数组
        System.out.println(s1.toUpperCase());
        char[] chars = s1.toCharArray();
        System.out.println(chars);

        //格式化
        String s7 = String.format("%d-%d-%d",2025, 3, 10);
        System.out.println(s7);
        //字符串替换
        String s8 = s1.replaceAll("ang", "555");
        System.out.println(s8);
        System.out.println(s1.replaceFirst("ang", "8888"));
        //拆分字符串
        String[] ret = s1.split(" ");
        System.out.println(Arrays.toString(ret));
        for (String tmp : ret){
            System.out.println(tmp);
        }
        String s9 = "www.133529529@qq.com#666";
        ret = s9.split("\\.|@|#");
        System.out.println(Arrays.toString(ret));
        //截取字符串
        System.out.println(s9.substring(4, 20));

        s9 = "       www.133529529@qq.com#666      ";
        System.out.println("[" + s9 + "]");
        System.out.println("[" + s9.trim() + "]");

    }
}

